<?php

namespace Modules\Web\Http\Controllers;

use HiCommon\Service\OrderCheckpointRefundService;
use HiCommon\Service\OrderCheckpointService;
use HiCommon\Service\OrderService;
use HiCommon\Service\PayRefundService;
use Illuminate\Support\Facades\Request;
use Modules\Api\Service\CheckpointOrderService;

class OrderCheckpointController extends BaseController
{
    public function index(){

    }

    /************************************************** 预约单 **************************************************/


    /**
     * 检测站-接单（年检预约订单-待处理）
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function waiting_list(){
        try {
            $arr_input = Request::input();
            $n_shop_id = intval(get_web_shop_id());
            $res = CheckpointOrderService::api_waiting_order_list_by_shopid($n_shop_id,$arr_input);
            return  $res;
        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }
    }

    /**
     * 检测站-订单列表（年检预约订单-已完成）
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function complete_list(){
        try {
            $arr_input = Request::input();
            $n_shop_id = intval(get_web_shop_id());
            $res = CheckpointOrderService::api_complete_order_list_by_shopid($n_shop_id,$arr_input);
            return  $res;
        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }

    }

    /**
     * 检测站-订单详情
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function order_detail(){
        try {
            $n_id = intval(Request::input('id'));
            return OrderService::api_checkpoint_order_detail($n_id);
        }
        catch (\Exception $exception) {
            return ['state'=>1,'msg'=>'失败','data'=>[],'error'=>$exception->getMessage()];
        }
    }


    /************************************************** 预约单操作 **************************************************/

    /*年检预约单-检测成功-合格*/
    public function single_check_success_ok(){
        try {
            $n_id = intval(Request::input('id',0));
            $n_shop_id = intval(get_web_shop_id());
            shiwu_start();
            $res = OrderCheckpointService::api_deal_complete_single($n_id,$n_shop_id);
            shiwu_end($res);
            return  $res;
        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }
    }

    /*年检预约单-检测成功-不合格*/
    public function single_check_success_not_ok(){
        try {
            $n_id = intval(Request::input('id',0));
            $n_shop_id = intval(get_web_shop_id());
            shiwu_start();
            $res = OrderCheckpointService::api_single_check_not_ok($n_id,$n_shop_id);
            shiwu_end($res);
            return  $res;
        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }
    }

    /*年检预约单-检测失败-不符合检测条件*/
    public function single_check_fail(){
        try {
            $n_id = Request::input('id',0);
            $n_shop_id = intval(get_web_shop_id());
            $s_remark = trim(Request::input('remarks',''));
            $s_fail_type = trim(Request::input('fail_type',''));
            shiwu_start();
            $res = OrderCheckpointService::api_deal_fail_single($n_id,$n_shop_id,$s_remark,$s_fail_type);
            shiwu_end($res);
            return  $res;

        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }
    }


    /************************************************** 预约单售后 **************************************************/

    /*售后列表*/
    public function after_sale_order_list(){
        try {
            $n_shop_id = intval(get_web_shop_id());
            return CheckpointOrderService::api_aftersale_list_by_shopid($n_shop_id);
        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }
    }

    /*售后详情*/
    public function after_sale_order_detail(){
        try {
            $n_id = intval(Request::input('id',0));
            return CheckpointOrderService::api_aftersale_detail_for_shop($n_id);
        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }
    }

    /*同意退款申请*/
    public function agree_refund_apply(){
        try {
            $n_id = Request::input('id',0);
            shiwu_start();
            $res = OrderCheckpointRefundService::api_apply_refund_agree($n_id);
            shiwu_end($res);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*拒绝退款申请*/
    public function confuse_refund_apply(){
        try {
            $n_id = Request::input('id',0);
            $s_refuse_reason = Request::input('refuse_reason',0);

            shiwu_start();
            $res = OrderCheckpointRefundService::api_apply_refund_refuse($n_id,$s_refuse_reason);
            shiwu_end($res);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*同意退款*/
    public function agree_refund_money(){
        try {
            $s_order_sn = str_trim(Request::input('order_sn',''));
            $s_refund_sn = str_trim(Request::input('refund_sn',''));

            shiwu_start();

            $res = PayRefundService::api_online_pay_refund($s_order_sn,$s_refund_sn);
            shiwu_end($res);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }










//
//    /**
//     * 年检预约订单 - 检测完成(单辆车)
//     *
//     * @return array
//     * @author wumengmeng <wu_mengmeng@foxmail.com>
//     */
//    public function single_complete(){
//        try {
//            $n_id = Request::input('id',0);
//            $n_shop_id = intval(get_web_shop_id());
//
//            shiwu_start();
//            $res = OrderCheckpointService::api_deal_complete_single($n_id,$n_shop_id);
//            shiwu_end($res);
//            return  $res;
//        }
//        catch (\Exception $exception) {
//            return hello_error('失败',[],$exception->getMessage());
//        }
//    }
//
//    /**
//     * 年检预约订单 - 检测失败(单辆车-退款)-操作
//     *
//     * @return array
//     * @author wumengmeng <wu_mengmeng@foxmail.com>
//     */
//    public function single_fail(){
//        try {
//            $n_id = Request::input('id',0);
//            $n_shop_id = intval(get_web_shop_id());
//            $s_remark = trim(Request::input('remarks',''));
//            $s_fail_type = trim(Request::input('fail_type',''));
//            shiwu_start();
//            $res = OrderCheckpointService::api_deal_fail_single($n_id,$n_shop_id,$s_remark,$s_fail_type);
//            shiwu_end($res);
//            return  $res;
//        }
//        catch (\Exception $exception) {
//            return hello_error('失败',[],$exception->getMessage());
//        }
//    }

}
